package com.elsa.common.configure;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.elsa.common.interceptor.ElsaServerProtectInterceptor;
/**
 * @projectName：elsa-common
 * @typeName：ElsaServerProtectConfigure
 * @author：cos
 * @date：2021年5月12日
 * @version
 * @desc：微服务防护配置类，使ElsaServerProtectInterceptor拦截器生效
 */
public class ElsaServerProtectConfigure implements WebMvcConfigurer {
    @Bean
    @ConditionalOnMissingBean(value = PasswordEncoder.class)
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
    @Bean
    public HandlerInterceptor elsaServerProtectInterceptor() {
        return new ElsaServerProtectInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(elsaServerProtectInterceptor());
    }
}
